﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace ProjectRoughWork
{
    class WeightedEdge
    {

        /// <summary>
        /// Default constructor. Initializes nodes connected to the edge to the ones given and calculates the weight of the edge
        /// </summary>
        /// <param name="node1"></param>
        /// <param name="node2"></param>

        public WeightedEdge(Node node1, Node node2)
        {
            connectedNodes = new Node[2];
            connectedNodes[0] = node1;
            connectedNodes[1] = node2;

            weight = Math.Abs((node1.Position - node2.Position).Length());

            connectionColor = Color.Red;
        }

        /// <summary>
        /// Accessor and Mutator for the edge's weight
        /// </summary>

        public float Weight
        {
            get { return weight; }
            set { weight = value; }
        }

        /// <summary>
        /// Accessor and mutator for the edge's color
        /// </summary>

        public Color ConnectionColor
        {
            get { return connectionColor; }
            set { connectionColor = value; }
        }

        /// <summary>
        /// Method to retrieve the node on the other end of the edge from the one given
        /// </summary>
        /// <param name="node">The opposing node of the one to be retrieved</param>
        /// <returns>The node on the other end of the edge from the input node</returns>

        public Node adjacentNode(Node node)
        {
            if (connectedNodes[0] == node)
            {
                return connectedNodes[1];
            }
            else if (connectedNodes[1] == node)
            {
                return connectedNodes[0];
            }

            return null;
        }

        /// <summary>
        /// Returns nodes of the edge
        /// </summary>
        /// <returns>Array containing the nodes on each end of the edge</returns>

        public Node[] getConnectedNodes()
        {
            return connectedNodes;
        }

        //Data Members

        Node[] connectedNodes;
        float weight;
        Color connectionColor;
    }
}
